angular.module('Controller')
.controller('QgyRepairManageEditCtrl',($scope,urls,$localStorage,NgTableParams,commonUtil,cryptUtil,wfAlert,commonConstant,$http, $uibModalInstance, items)->
    $scope.type=type=items.type
    $scope.data=data=items.data
    $scope.modalTitle=if type=='view' then '报修详情' else '报修处理'
    $scope.modalEnableList=commonConstant.enabledList()
    $scope.repairStatusList=commonConstant.repairStatusList(true)
    loadImageParam=()->
        if data.image.indexOf('[')==0
            imageList=JSON.parse(data.image)
            if imageList && imageList.length>0
                data.imagePicture=imageList[0]
            else
                data.imagePicture=undefined
        else
            data.imagePicture=data.image
    loadImageParam()
    $scope.repairDealStatusList=[
        {value:2, name:'待维修'}
        {value:4, name:'待评价'}
    ]
    $scope.needFeeList=[
        {value:true,name:'是'}
        {value:false,name:'否'}
    ]
    editData=()->
        reqData={
            "buzItem":$scope.data.buzItem
            "providerName":$scope.data.providerName
            "providerPhone": $scope.data.providerPhone
            "providerFeedback":$scope.data.providerFeedback
            "needFee":$scope.data.needFee
            "repairFee":Number($scope.data.repairFee)
            "dealResult": $scope.data.dealResult
            "status":$scope.data.status
        }
        if $scope.data.providerTime
            reqData.providerTime=moment($scope.data.providerTime).format('YYYY-MM-DD HH:mm:ss')
        $http.put("/repair/#{$scope.data.id}",reqData)
        .success((resp)->
            if resp.code==0
                wfAlert.toastInfo($scope.modalTitle+'成功')
                $uibModalInstance.close('done')
            else
                wfAlert.toastError(resp.message)
        )
    $scope.isNeedFee = (val)->
        if val
            $scope.repairDealStatusList=[
                {value:2, name:'待维修'}
            ]
        else
            $scope.repairDealStatusList=[
                {value:2, name:'待维修'}
                {value:4, name:'待评价'}
            ]

    $scope.confirm = ()->
        if type=='view'
            $uibModalInstance.dismiss('cancel')
        else
            editData()
    $scope.cancel =()->
        $uibModalInstance.dismiss('cancel')
)